#ifndef _ONET_INCLUDE_C_SETTINGS_
#define _ONET_INCLUDE_C_SETTINGS_

/*!
    Copright: Kai "DrHalan" Mast - www.freakybytes.org

    This file is part of OpenNetwork. See OpenNetwork.h for license information.
*/

#include <string>
#include <map>
#include <iostream>
#include <fstream>
#include <cstdio>
#include <sstream>
#include <cstdlib>
#include <OpenNetwork/types.h>

namespace onet
{

//! A simple class to manage a settings file
//! Templates are  not used here due to specific conversion needed
//! Also you don't depend on every bit here 3 file types should do the job

class CSettings
{
    public:
        CSettings(bool autoSave_ = true);
        ~CSettings();

        //! Set the file manually
            //! Use absolute path!
        void setFile(std::string str);

        //! Automatically creates/reads a file in the private folder of the user
        void autoSetFile(std::string str, bool hidden = true);

        //! Saves the config to the file
        bool save();

        //! Load config from file
        bool load();

        //! Gets the path/name of config-file
        std::string getFileName();

        //! Sets values
        void setString(std::string name, std::string val);
        void setInteger(std::string name, s32 val);
        void setBool(std::string name, bool val);

        //! Gets values
        //! Def is a fallback value if value doesn't exsist
        s32 getInteger(std::string name, s32 def = 0);
        bool getBool(std::string name, bool def = false);
        std::string getString(std::string name, std::string def = std::string(""));

        //! Is saving on quitting?
        bool isAutoSaving();
        void setAutoSaving(bool newval);

        //! Is file loaded?
        bool isLoaded();

    private:
        //! A hash holding all values according to their names
        std::map<std::string, std::string> values;

        //! The name of the config-file
        std::string fileName;

        //! Save file on quit?
        bool autoSave;

        //! Is file loaded?
        bool loaded;
};

}

#endif
